<?php
/**
 * 检查权限管理的二级菜单
 */

$host = '113.44.136.17';
$port = 3306;
$database = 'qiandao';
$username = 'qiandao';
$password = 'NGbks3HWx5PhSxDX';

try {
    $pdo = new PDO("mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
    echo "=== 检查权限管理菜单 ===\n\n";
    
    // 查找权限管理菜单
    $stmt = $pdo->query("SELECT id, pid, title, node FROM system_menu WHERE title LIKE '%权限%' ORDER BY pid, id");
    $menus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($menus as $menu) {
        $level = $menu['pid'] == 0 ? '一级' : '二级';
        echo "{$level}菜单 | ID:{$menu['id']} | PID:{$menu['pid']} | 标题:{$menu['title']} | 节点:{$menu['node']}\n";
    }
    
    echo "\n=== 查找用户管理菜单 ===\n";
    $stmt = $pdo->query("SELECT id, pid, title, node FROM system_menu WHERE title LIKE '%用户%' ORDER BY pid, id");
    $menus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    foreach ($menus as $menu) {
        $level = $menu['pid'] == 0 ? '一级' : '二级';
        echo "{$level}菜单 | ID:{$menu['id']} | PID:{$menu['pid']} | 标题:{$menu['title']} | 节点:{$menu['node']}\n";
    }
    
    echo "\n=== 查找 PID=42 的所有子菜单 ===\n";
    $stmt = $pdo->query("SELECT id, pid, title, node, status FROM system_menu WHERE pid = 42");
    $menus = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    if (empty($menus)) {
        echo "❌ 没有找到 PID=42 的子菜单！\n";
        echo "需要手动添加子菜单\n";
    } else {
        foreach ($menus as $menu) {
            $status = $menu['status'] == 1 ? '启用' : '禁用';
            echo "ID:{$menu['id']} | 标题:{$menu['title']} | 节点:{$menu['node']} | {$status}\n";
        }
    }
    
} catch (PDOException $e) {
    echo "数据库错误: " . $e->getMessage() . "\n";
}

